package com.stx.dao.impl;


import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import com.stx.dao.MaintainedDao;
import com.stx.domain.Building;
import com.stx.domain.Maintained;
import com.stx.domain.Maintaining;
@Repository
public class MaintainedDaoImpl implements MaintainedDao {
	@Resource
	private JdbcTemplate jt;
	@Override
	public void addMaintainedByT(Maintaining main) {
		// TODO Auto-generated method stub
		Date date=new Date();
		  DateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		  String time=format.format(date);
		String sql="insert into MAINTAININGRESULT values(id.nextval,?,?,?,?,?,?,?,?)";
		Object[] obj={main.getTime(),main.getNo(),main.getName(),main.getD(),main.getThing(),"已处理",time,main.getRemark()};
		jt.update(sql,obj);
	}
	@Override
	public List selectMaintainedByT() {
		// TODO Auto-generated method stub

		String sql="select * from MAINTAININGRESULT";
		List list=jt.query(sql, new info());
		return list;
	}
	class info implements RowMapper{
		@Override
		public Object mapRow(ResultSet rs, int arg1) throws SQLException {
			Maintained m=new Maintained();
			m.setTime(rs.getString("time"));
			m.setNo(rs.getInt("no"));
			m.setName(rs.getString("name"));
			m.setD(rs.getString("d"));
			m.setThing(rs.getString("thing"));
			m.setResult(rs.getString("result"));
			m.setResulttime(rs.getString("resulttime"));
			m.setRemark(rs.getString("remark"));
		
			return m;
		}
		
	}
}
